package com.kgc.service.impl;

import com.kgc.dao.GoodsDetailDao;
import com.kgc.entity.GoodSort;
import com.kgc.entity.GoodsDetail;
import com.kgc.service.GoodsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class GoodsDetailServiceImpl implements GoodsDetailService {
    @Autowired
    private GoodsDetailDao dao;
    @Override
    @Transactional(readOnly = true)
    public List<GoodsDetail> select(String name,int currentPage) {
        Map<String,Object>paramMap=new HashMap<>();
        paramMap.put("start",(currentPage - 1) * 6);
        if(!"0".equals(name)){
            paramMap.put("name",name);
        }
        return dao.select(paramMap);
    }

    @Override
    @Transactional(readOnly = true)
    public int countGood(String name) {

        Map<String,Object>paramMap=new HashMap<>();
        if(!"0".equals(name)){
            paramMap.put("name",name);
        }
        return dao.countGood(paramMap);
    }

    @Override
    @Transactional(readOnly = true)
    public List<GoodSort> selectGoodSort() {
        return dao.selectGoodSort();
    }
}
